home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1923 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.unix.osf.osf1,comp.lang.c
  4. Subject: Re: printf-problem
  5. Date: 17 Jan 1996 21:18:24 GMT
  6. Organization: Computer People Inc.
  7. Distribution: world
  8. Message-ID: <ALUN.CHAMPION.96Jan17161824@g7240065.bridge.bst.bls.com>
  9. References: <4dj4g6$t9f@sunsystem5.informatik.tu-muenchen.de>
  10. NNTP-Posting-Host: bstfirewall.bst.bls.com
  11. In-reply-to: wist@lam.mw.tu-muenchen.de's message of 17 Jan 1996 15:27:02 GMT
  12.  
  13. In article <4dj4g6$t9f@sunsystem5.informatik.tu-muenchen.de> wist@lam.mw.tu-muenchen.de (Henrik Wist) writes:
  14.  
  15. : long int zahl;   /* which is e.g. 10000500001 */
  16. : printf("%d\n",zahl);      /* gives 1410565409, which is definitly wrong */
  17.  
  18. Though the FAQ goes into a lot of detail about printf and scanf, but it
  19. sort of misses this one. The closes it gets is in the answer to 
  20. "How can I convert numbers to strings (the opposite of atoi)?"
  21. In the answer it says :- 
  22.         You can obviously use sprintf() to convert long or floating-
  23.         point numbers to strings as well (using %ld or %f).
  24.  
  25. I suppose the answer is there ;')
  26.  
  27. Anyway the answer is %d is the printf specifier for ints not longs
  28. %ld is the printf specifier for longs. Man pages and/or almost any book
  29. on 'C' could have told you this.
  30.  
  31. Regards
  32.  
  33.    -A.
  34. -- 
  35. | A.Champion                |
  36.